package com.lz.football.module.activity.accumulateConsumption
{
	import com.common.utils.Reflection;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.message.http.JsClient;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.activity.IActivity;
	
	import common.BaseView.BaseView;
	import common.BaseView.GoodItem;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.text.TextField;

	/**
	 *累积消费 
	 * @author Administrator
	 * 
	 */	
	public class AccumulateConsumptionView extends BaseView implements IActivity
	{
		
		/**
		 *总消费 
		 */
		private var allconsumption:TextField;
		/**
		 *当前消费 
		 */
		private var curconsumption:TextField;
		/**
		 *充值按钮 
		 */
		private var topUpBtn:SimpleButton;
		/**
		 *活动时间 
		 */
		private var time:TextField;
		/**
		 *进度条 
		 */
		private var pro:MovieClip;
		
		/**
		 *当前消费奖励 
		 */
		private var currList:Array = [[5,15],[6,16],[5,18],[6,18],[6,17]];
		
		/**
		 *累积消费 
		 */
		private var allList:Array = [[7,13],[6,14],[2,27],[6,28],[6,7]];
		private var itemList:Array;
		private var btn_1:SimpleButton;
		private var btn_2:SimpleButton;
		private var btn_3:SimpleButton;
		private var btn_4:SimpleButton;
		private var btn_5:SimpleButton;
		private var btn_6:SimpleButton;
		private var btn_7:SimpleButton;
		private var btn_8:SimpleButton;
		private var btn_9:SimpleButton;
		private var btn_10:SimpleButton;
		public function AccumulateConsumptionView()
		{
			super();
		}
		
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.activity.accConView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.accConBg;
			_viewHeight = _windowBg.height;
			_viewWidth = _windowBg.width;
			allconsumption = symbolSkin.allconsumption
			curconsumption = symbolSkin.curconsumption;
			topUpBtn = symbolSkin.topUpBtn;
			time = symbolSkin.time;
			pro = symbolSkin.pro;
			pro.gotoAndStop(1);
			allconsumption.text = "0/100000";
			btn_1 = symbolSkin.btn_1
			btn_2 = symbolSkin.btn_2;
			btn_3 = symbolSkin.btn_3;
			btn_4 = symbolSkin.btn_4;
			btn_5 = symbolSkin.btn_5;
			btn_6 = symbolSkin.btn_6;
			btn_7 = symbolSkin.btn_7;
			btn_8 = symbolSkin.btn_8;
			btn_9 = symbolSkin.btn_9;
			btn_10 = symbolSkin.btn_10;
			
			
			btn_1.mouseEnabled = btn_2.mouseEnabled =btn_3.mouseEnabled =btn_4.mouseEnabled =btn_5.mouseEnabled  = false;
			btn_6.mouseEnabled = btn_7.mouseEnabled =btn_8.mouseEnabled =btn_9.mouseEnabled =btn_10.mouseEnabled  = false;
			
			var time:TextField = symbolSkin.time;
			var xml:XML = ResourceManager.instance.getResource(ResourceConst.ACTIVITYTIME_XML);
			time.text = "活动时间：" +xml.activity9 + "截止";;
			
			isCloseBtn = true;
			isDrag = true;
			moveClose(_viewWidth - 30,38);
			onResizeHandler();
			addEvtListener();
			initItem();
			
			
		}
		private function initItem():void
		{
			itemList = [];
			var len:int = currList.length;
			var i:int;
			var item:GoodItem;
			for(i = 0;i < len;i++)
			{
				item = new GoodItem();
				item.initUI();
				item.data = AppData.getInstance().goodsManager.getGoodsByTypeAndId(currList[i][0],currList[i][1]);
				item.x = 63 + 125* i;
				item.y = 156;
				this.addChild(item);
				itemList.push(item);
			}
			
			for(i = 0;i < len;i++)
			{
				item = new GoodItem();
				item.initUI();
				item.data = AppData.getInstance().goodsManager.getGoodsByTypeAndId(allList[i][0],allList[i][1]);
				item.x = 63 + 125* i;
				item.y = 314;
				this.addChild(item);
				itemList.push(item);
			}
		}
		override public function addEvtListener():void
		{
			topUpBtn.addEventListener(MouseEvent.CLICK,onTopupHandler);
			btn_1.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_2.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_3.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_4.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_5.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_6.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_7.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_8.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_9.addEventListener(MouseEvent.CLICK,onGetHandler);
			btn_10.addEventListener(MouseEvent.CLICK,onGetHandler);
			
		}
		
		/**
		 *领取奖励 
		 * @param event
		 * 
		 */
		protected function onGetHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			var type:int;
			switch(event.currentTarget)
			{
				case btn_1:
					type = 1;
					break;
				case btn_2:
					type = 2;
					break;
				case btn_3:
					type = 3;
					break;
				case btn_4:
					type = 4;
					break;
				case btn_5:
					type = 5;
					break;
				case btn_6:
					type = 6;
					break;
				case btn_7:
					type = 7;
					break;
				case btn_8:
					type = 8;
					break;
				case btn_9:
					type = 9;
					break;
				case btn_10:
					type = 10;
					break;
			}
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_ACCCON_AWARD,{type:type}));
		}
		
		protected function onTopupHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			JsClient.recharge();
		}
		
		override public function removeEvtListener():void
		{
			topUpBtn.removeEventListener(MouseEvent.CLICK,onTopupHandler);
			btn_1.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_2.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_3.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_4.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_5.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_6.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_7.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_8.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_9.removeEventListener(MouseEvent.CLICK,onGetHandler);
			btn_10.removeEventListener(MouseEvent.CLICK,onGetHandler);
			super.removeEvtListener();
		}
		/**
		 *设置按钮状态 
		 * 
		 */
		private function setButtonStatus($btn:SimpleButton,value:int):void
		{
			switch(value)
			{
				case 0:
					$btn.filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
						0.3086, 0.6094, 0.082, 0, 0,
						0.3086, 0.6094, 0.082, 0, 0,
						0,0,0,1,0,])];
					$btn.mouseEnabled = false;
					
					break;
				case 1:
					$btn.filters = null;
					$btn.mouseEnabled = true;
					
					break;
				case 2:
					$btn.visible = false;
					$btn.mouseEnabled = false;
					$btn.filters = null;
					break;
			}
		}
		override public function destroyView():void
		{
			var item:GoodItem;
			while(itemList.length)
			{
				item = itemList.pop();
				item.destroyView();
				item = null;
			}
			itemList = null;
			removeEvtListener();
			super.destroyView();
		}
		
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ModuleEvent.REMOVE_MODULE));
		}
		/**
		 *信息 
		 * @param $obj
		 * 
		 */		
		public function baseinformation($obj:Object):void
		{
			curconsumption.text = $obj.daycashpoint + "";
			allconsumption.text = $obj.activecashpoint + "/100000";
			var per:int = Math.ceil(($obj.activecashpoint / 100000) * 100);
			if(per < 0) per = 0;
			if(per > 100)per = 100;
			pro.gotoAndStop(per);
			
			setButtonStatus(btn_1,$obj.status15);
			setButtonStatus(btn_2,$obj.status16);
			setButtonStatus(btn_3,$obj.status17);
			setButtonStatus(btn_4,$obj.status18);
			setButtonStatus(btn_5,$obj.status19);
			setButtonStatus(btn_6,$obj.status20);
			setButtonStatus(btn_7,$obj.status21);
			setButtonStatus(btn_8,$obj.status22);
			setButtonStatus(btn_9,$obj.status23);
			setButtonStatus(btn_10,$obj.status24);
		}
		/**
		 *领取奖励返回 
		 * @param $obj
		 * 
		 */		
		public function award($obj:Object):void
		{
//			switch($obj.type)
//			{
//				case 1:
//					setButtonStatus(btn_1,2);
//					break;
//				case 2:
//					setButtonStatus(btn_2,2);
//					break;
//				case 3:
//					setButtonStatus(btn_3,2);
//					break;
//				case 4:
//					setButtonStatus(btn_4,2);
//					break;
//				case 5:
//					setButtonStatus(btn_5,2);
//					break;
//			}
			setButtonStatus(this["btn_" + $obj.type] ,2);
		}
	}
}